def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

def find_nearest_prime(num):
    lower = num
    upper = num
    while True:
        if is_prime(lower):
            return lower
        if is_prime(upper):
            return upper
        lower -= 1
        upper += 1

number_words = input().split()
if len(number_words) != 3:
    print("Wrong input")
else:
    number_dict = {"zero": 0, "one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9}
    try:
        number = int("".join(str(number_dict[word]) for word in number_words))
        print(find_nearest_prime(number))
    except (ValueError, KeyError):
        print("Wrong input")
